<?php

/**
 * This is the model class for table "group_data".
 *
 * The followings are the available columns in table 'group_data':
 * @property integer $group_data_ID
 * @property string $name
 * @property string $description
 * @property string $address
 * @property string $leader
 * @property integer $leader_ID
 * @property string $email
 * @property string $phone
 * @property string $created
 *
 * The followings are the available model relations:
 * @property Group[] $groups
 * @property User $leader0
 */
class GroupData extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return GroupData the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'group_data';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('name, leader, email', 'length', 'max'=>100),
			array('description', 'length', 'max'=>2000),
			array('address, phone', 'length', 'max'=>45),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('group_data_ID, name, description, address, leader, leader_ID, email, phone, created', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'groups' => array(self::HAS_MANY, 'Group', 'group_data_ID'),
			'leader0' => array(self::BELONGS_TO, 'User', 'leader_ID'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'group_data_ID' => 'Group Data',
			'name' => 'Name',
			'description' => 'Description',
			'address' => 'Address',
			'leader' => 'Leader',
			'leader_ID' => 'Leader',
			'email' => 'Email',
			'phone' => 'Phone',
			'created' => 'Created',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('group_data_ID',$this->group_data_ID);
		$criteria->compare('name',$this->name,true);
		$criteria->compare('description',$this->description,true);
		$criteria->compare('address',$this->address,true);
		$criteria->compare('leader',$this->leader,true);
		$criteria->compare('leader_ID',$this->leader_ID);
		$criteria->compare('email',$this->email,true);
		$criteria->compare('phone',$this->phone,true);
		$criteria->compare('created',$this->created,true);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}